using System;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using Dimok.Data;

namespace Dimok.Menu{

	////////////////////////////////////////////////////////////////////////////////////////////////////
	/// <summary>	Action. </summary>
	///
	/// <remarks>	Dimon, 12/21/2010. </remarks>
	////////////////////////////////////////////////////////////////////////////////////////////////////

	public class Action : System.Web.UI.UserControl {
		protected Repeater rptActions;
		protected Literal ltrAttrs;
		public string Direction = "";

		////////////////////////////////////////////////////////////////////////////////////////////////////
		/// <summary>	Gets the dir. </summary>
		///
		/// <value>	The dir. </value>
		////////////////////////////////////////////////////////////////////////////////////////////////////

		public string Dir{get{return Direction;}}

		////////////////////////////////////////////////////////////////////////////////////////////////////
		/// <summary>	Gets the on click. </summary>
		///
		/// <value>	The on click. </value>
		////////////////////////////////////////////////////////////////////////////////////////////////////

		public string OnClick{get{return (Attributes["OnClick"]+"") == "" ? "sendToMenu" : Attributes["OnClick"];}}

		////////////////////////////////////////////////////////////////////////////////////////////////////
		/// <summary>	Event handler. Called by Page for load events. </summary>
		///
		/// <remarks>	Dimon, 12/21/2010. </remarks>
		///
		/// <exception cref="Exception">	Thrown when exception. </exception>
		///
		/// <param name="sender">	Source of the event. </param>
		/// <param name="e">			Event information. </param>
		////////////////////////////////////////////////////////////////////////////////////////////////////

		private void Page_Load(object sender, System.EventArgs e) {
			if( (Attributes["DIR"]+"") != "" )Direction = Attributes["DIR"]+"";
			UserPageEx page = Page as Dimok.Data.UserPageEx;
			UserObjectEx uox = page == null ? new UserObjectEx() : page.uox;
			switch( Direction.ToUpper() ){
				case "F":
					rptActions.DataSource = uox.menusNext.Tables[0];
					break;
				case "B":
					rptActions.DataSource = uox.menusPrev.Tables[0];
					break;
				default: throw new Exception("Unrecognized DIR["+Direction+"] attribute.");
			}
			rptActions.DataBind();
		}

		#region Web Form Designer generated code

		////////////////////////////////////////////////////////////////////////////////////////////////////
		/// <summary>	Raises the initialise event. </summary>
		///
		/// <remarks>	Dimon, 12/21/2010. </remarks>
		///
		/// <param name="e">	Event information to send to registered event handlers. </param>
		////////////////////////////////////////////////////////////////////////////////////////////////////

		override protected void OnInit(EventArgs e) {
			//
			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
			//
			InitializeComponent();
			base.OnInit(e);
		}

		////////////////////////////////////////////////////////////////////////////////////////////////////
		/// <summary>	
		/// Required method for Designer support - do not modify the contents of this method with the code
		/// editor. 
		/// </summary>
		///
		/// <remarks>	Dimon, 12/21/2010. </remarks>
		////////////////////////////////////////////////////////////////////////////////////////////////////

		private void InitializeComponent() {
			this.Load += new System.EventHandler(this.Page_Load);
		}
		#endregion
	}
}

